Developer --> Technical Publications
PATHHardware Documentation > USB Devices > Mac OS USB DDK API Reference


Device Management Functions

The functions here provide a mechanism for the hub driver to inform the USB Manager of the addition of a new device to a specified USB and to retrieve the USB device ID of the new USB device. The USB hub driver tasks include assigning the device address and preparing the device's default pipe for use. This is the process of enumerating a device for use on the USB.

The functions in this section are called in a specific sequence to perform proper device enumeration on the USB. The function calling sequence is as follows:

  1. Call the USBHubAddDevice function
  2. When USBHubAddDevice completes, the hub driver is clear to reset the device.
  3. Reset the port for that device
  4. Obtain the port status from the hub to get the speed of the device.
  5. Call USBHubConfigurePipeZero to set the device speed and packet size.
  6. Perform any necessary communication with the device.
  7. Call the USBHubSetAddress function to set the address of the device which is used for future communication by the hub driver and other drivers interested in the device.

USBHubAddDevice

The USBHubAddDevice function informs the USB that the hub driver has a new device that needs to be added to the USB.

At the time the device first appears on the USB, it has not yet been reset. When the completion routine for this function is called, it is safe for the hub driver to reset the device. The hub driver should then read the device descriptor to get the endpoint and maxpacket size. The driver must then call the USBHubSetAddress function, even if an error occurs. There is a 1 second timeout allowed, if USBHubSetAddress is not called, it will be called for you. This is done to prevent the bus enumeration mechanism from halting further system activity.

OSStatus USBHubAddDevice(USBPB *pb);

Required fields in the USBPB parameter block for the USBHubAddDevice function are

--> pbLength
Length of parameter block
--> pbVersion
Parameter block version number
--> usbCompletion
The completion routine
--> usbRefcon
General-purpose value passed back to the completion routine
<-- usbReference
Device reference

The device reference can be used to address the device while it is device 0. This reference becomes invalid as soon as it is addressed with the USBHudSetAddress function.

There must be a valid USBReference passed in the usbReference field of the parameter block. If a nil value or a reference that does not match an existing device, interface, or pipe is passed in, the call returns immediately with an unknown device error.

If the device associated with this call is unplugged and its driver removed while this function call is pending, the function will not complete.

USBHubConfigurePipeZero

The USBHubConfigurePipeZero function must be called after a device is reset, and before any attempt is made to communicate with the device at its default address zero.

OSStatus USBHubConfigurePipeZero(USBPB *pb);

Required fields in the USBPB parameter block for the USBHubConfigurePipeZero function are

--> pbLength
Length of parameter block
--> pbVersion
Parameter block version number
--> usbCompletion
The completion routine
--> usbRefcon
General-purpose value passed back to the completion routine
--> usbReference
Device zero reference returned from the USBHubAddDevice function.
--> usbFlags
Device speed 0 or 1: slow (1 indicates a low speed device)
--> usbWValue
maxPacketSize, obtained from the device descriptor

USBHubSetAddress

The USBHubSetAddress function addresses the currently unaddressed device (The device has been reset and is responding as device 0.) and creates a device reference for it. After this function completes, the device can be addressed with device requests using the new device reference.

OSStatus USBHubSetAddress(USBPB *pb);

Required fields in the USBPB parameter block for the USBHubSetAddress function are

--> pbLength
Length of parameter block
--> pbVersion
Parameter block version number
--> usbCompletion
The completion routine
--> usbRefcon
General-purpose value passed back to the completion routine
<--> usbReference
--> Reference from USBHubAddDevice call <-- New device reference
--> usbFlags
0 or 1: (1 indicates a low speed device)
--> usbWValue
maxPacketSize of endpoint 0, obtained from the device descriptor

USBHubDeviceRemoved

The USBHubDeviceRemoved function causes all pipes open to the specified device to be closed, thus removing the device.

OSStatus USBHubDeviceRemoved(USBPB *pb);

Required fields in the USBPB parameter block for the USBHubDeviceRemoved function are

--> pbLength
Length of parameter block
--> pbVersion
Parameter block version number
--> usbCompletion
The completion routine
--> usbRefcon
General-purpose value passed back to the completion routine
--> usbReference
Device reference
--> usbFlags
Should be set to 0

The hub driver should also call the USBExpertRemoveDeviceDriver function to inform the USB Manager. This removes the class driver associated with the device. If the device is a hub, the hub driver should make the device removal calls for all devices attached to the hub. The USB Manager is responsible for determining what if any downstream devices are connected to the hub and disconnecting them to remove that hub's tree of devices.


© 1998 Apple Computer, Inc. – (Last Updated 23 Nov 98)

Previous | Back Up One Level | Next |